#顺序表
tree_a = [None,'a','b','c','d','e','f','g','h']
class TreeNode(object):
    def __init__(self, data=0):
        self.data = data
        self.left = None
        self.right = None
class Tree:
    def __init__(self,maxNodes):
        self.root = None
        self.nodes = [TreeNode() for i in range(maxNodes)]
        self.nodesize = maxNodes
    def GetTreeNode(self,id):
        return self.nodes[id]
    def create(self,arr,size,nodeId):
        if nodeId >= size or arr[nodeId] == None:
            return None
        nowNode = self.GetTreeNode(nodeId)
        nowNode.data = arr[nodeId]
        nowNode.left = self.create(arr,size,2*nodeId)
        nowNode.right = self.create(arr,size,2*nodeId+1)
        return nowNode
def visit(root):
    if root is None:
        return
    print(root.data,end=' ')
#前序遍历
def Preorder_visit(root):
    if root is not None:
        visit(root)
        Preorder_visit(root.left)
        Preorder_visit(root.right)
#中序遍历
def  Midorder_visit(root):
    if root is not None:
        Midorder_visit(root.left)
        visit(root)
        Midorder_visit(root.right)
#后序遍历
def Postorder_visit(root):
    if root is not None:
        Postorder_visit(root.left)
        Postorder_visit(root.right)
        visit(root)
id = 1
tree = Tree(len(tree_a)).create(tree_a,len(tree_a),1)
Preorder_visit(tree)
print('\n')
Midorder_visit(tree)
print('\n')
Postorder_visit(tree)